package utils;

import javax.swing.text.AttributeSet;
import javax.swing.text.BadLocationException;
import javax.swing.text.PlainDocument;

public class MaxLenghtTextDocument extends PlainDocument {
	
	private int maxChars; //Store maximum characters permitted

	
	public MaxLenghtTextDocument (int maxChars) {
		super();
		this.maxChars = maxChars;
	}
	
	@Override
	public void insertString(int offs, String str, AttributeSet a)
	throws BadLocationException {
		if(str != null && (getLength() + str.length() < maxChars)){
			super.insertString(offs, str, a);
		}
	}

	public int getMaxChars() {
		return maxChars;
	}

	public void setMaxChars(int maxChars) {
		this.maxChars = maxChars;
	}

	
}
